<template>
  <div class="content-box">
    <nav-title title="教育经历" />
    <div class="line">
      <span class="important">*</span>
      <div class="label">开始时间</div>
      <div class="value">
        <group>
          <datetime :min-year="1900" :max-year="2100" value-text-align="left" placeholder="请选择" v-model="edus.startDt"></datetime>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important">*</span>
      <div class="label">结束时间</div>
      <div class="value">
        <group>
          <datetime :min-year="1900" :max-year="2100" value-text-align="left" placeholder="请选择" v-model="edus.endDt"></datetime>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important">*</span>
      <div class="label">学校名称</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="edus.cSchool">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">专业</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="edus.cMajor">
      </div>
    </div>
    <div class="line">
      <span class="important">*</span>
      <div class="label">学历</div>
      <div class="value">
        <group label-width="5em">
          <popup-radio placeholder="请选择" :options="educationList" v-model="edus.cEduciton"></popup-radio>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">学位</div>
      <div class="value">
        <group label-width="5em">
          <popup-radio placeholder="请选择" :options="degreeList" v-model="edus.cDegree"></popup-radio>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important">*</span>
      <div class="label">是否统招</div>
      <div class="value">
        <group label-width="5em">
          <popup-radio placeholder="请选择" :options="lcList" v-model="edus.cYesNo"></popup-radio>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important">*</span>
      <div class="label">是否最高学历</div>
      <div class="value">
        <group label-width="5em">
          <popup-radio placeholder="请选择" :options="lcList" v-model="edus.cYesNo1"></popup-radio>
        </group>
      </div>
    </div>
    <div class="submit-btn" @click="save">
      保存
    </div>
    <div class="remove-btn" @click="remove">
      删除
    </div>
  </div>

</template>

<script>
import { Datetime, Group, PopupRadio } from 'vux'
import { saveEducation,delEducation,getDicItem } from '../../../../api/api'
import { json2Form } from '../../../../util/http'

export default {

  name: 'input-information',
  components: {
    Datetime, Group, PopupRadio
  },
  mounted(){
    //获取字典
    this.getDic();
    if(this.$store.state.hid){
      this.edus.rsHireId = this.$store.state.hid
      this.eduDel.rsHireId = this.$store.state.hid
    }
  },
  data() {
    return {
      edus:{
        rsHireId: '',
      },

      eduDel:{
        rsHireId: '',
        cSeqno:''
      },

      educationList: [],
      educationLength: 1,
      education: [],

      degreeList: [],
      degreeLength: 1,
      degree: [],

      lcList: [{value: '是', key: 'Y'},{value: '否', key: 'N'}],
    }
  },
  created() {
    this.getEdus()
  },
  methods: {
    getDic(){
      //学历字典
      getDicItem({fileName: 'HIGHEST_EDUC_LVL'}).then(res=>{
        if(res && res.retCode === '000000'){
          for(let i=0; i<res.retData.length; i++){
            this.educationList.push({value: res.retData[i].xlatshortname,key: res.retData[i].fieldvalue});
          }
        }
      }).catch(res=>{

      });

      //学位字典
      getDicItem({fileName: 'C_DEGREE'}).then(res=>{
        if(res && res.retCode === '000000'){
          for(let i=0; i<res.retData.length; i++){
            this.degreeList.push({value: res.retData[i].xlatshortname,key: res.retData[i].fieldvalue});
          }
        }
      }).catch(res=>{

      });
    },
    save() {
      const that = this
      if(that.edus.startDt == ''){
        this.$vux.alert.show({
          title: '警告',
          content: '请选择开始时间'
        });
        return;
      }

      if(that.edus.endDt == ''){
        this.$vux.alert.show({
          title: '警告',
          content: '请选择结束时间'
        });
        return;
      }
      if(that.edus.cSchool == '' || that.edus.cSchool == undefined){
        this.$vux.alert.show({
          title: '警告',
          content: '请输入学校名称'
        });
        return;
      }

      if(that.edus.cEduciton == '' || that.edus.cEduciton == undefined){
        this.$vux.alert.show({
          title: '警告',
          content: '请选择学历'
        });
        return;
      }

      if(that.edus.cYesNo == '' || that.edus.cYesNo == undefined){
        this.$vux.alert.show({
          title: '警告',
          content: '请选择是否统招'
        });
        return;
      }

      if(that.edus.cYesNo1 == '' || that.edus.cYesNo1 == undefined){
        this.$vux.alert.show({
          title: '警告',
          content: '请选择是否最高学历'
        });
        return;
      }

      saveEducation(json2Form(that.edus)).then(res => {
        //成功：000000
        if(res && res.retCode === '000000' ){
          //保存成功
          // 显示
          this.$vux.alert.show({
            title: '提示',
            content: '保存成功',
            onHide () {
              that.$router.push('/informationCollection/userInfo');
            }
          })

        }else{
          // 显示
          this.$vux.alert.show({
            title: '',
            content: res.retMsg
          })
        }
      }).catch (res=>{
        this.$vux.alert.show({
          title: '警告',
          content: '网络异常，请稍后重试'
        })
      })

    },
    remove() {
      const _this = this;

      _this.$vux.confirm.show({
          // 组件除show外的属性
          title: '提示',
          content: '确定删除？',
          onCancel () {
          },
          onConfirm () {
            delEducation(json2Form(_this.eduDel)).then(res=>{
              //成功：000000
              if(res && res.retCode === '000000' ){
                //删除成功
                _this.$vux.alert.show({
                  title: '提示',
                  content: '删除成功',
                  onHide () {
                    _this.$router.push('/informationCollection/userInfo');
                  }
                })
              }else{
                // 显示
                _this.$vux.alert.show({
                  title: '',
                  content: res.retMsg
                })
              }

            })
            .catch(res=>{
              _this.$vux.alert.show({
                title: '',
                content: '网络异常，请稍后重试'
              })
            })

          }
        })
    },
    getEdus() {
      if(this.$route.params.edult){    
        this.edus = this.$route.params.edult
        this.eduDel.cSeqno = this.$route.params.edult.cSeqno
        console.log(this.$route.params.edult.nta)
      }
    }
  }
}
</script>
<style type="text/scss" lang="scss">
@import "./editinfo";
</style>
